<?php
class TestAll {
	public function testLH() {
		//Loginhandlertest
		$lh = new LoginHandler();
		//1st test, logout
		$testMessage = "<br/>" . "<h1>Loginhandlertestet: </h1><p>";
		$lh -> doLogout();
		if ($lh -> isLoggedIn() == true) {
			echo " 1a testet misslyckades. ";
			return false;
		}
		//2nd test, fail to log in
		if ($lh -> doLogin("Anna", "wrong password") == true) {
			echo " 2a testet misslyckades. ";
			return false;
		}
		//3d test, log in successfull
		if ($lh -> doLogin("Lisa", "123456") == false) {
			echo " 3e testet misslyckades. ";
			return false;
		}
		//4th test, check if user is logged in
		if ($lh -> isLoggedIn() == false) {
			echo " 4e testet misslyckades. ";
			return false;
		}
		//5th test, log out
		$lh -> doLogout();
		if ($lh -> isLoggedIn() == true) {
			echo " 5e testet misslyckades. ";
			return false;
		}
		//6th test, try to log in with wrong password
		if ($lh -> doLogin("Lisa", "5555") == true) {
			echo " 6e testet misslyckades. ";
			return false;
		}
		return true;
	}

	public function testCookies() {
		$lv = new LoginView();
		$name = "testCookie";
		$value = "testValue";
		// 1st cookie test, create cookie
		$lv -> createCookie($name, $value);
		if ((!$_COOKIE[$name]) == $value) {
			echo "Testet för att skapa en cookie misslyckades";
		}
		// 2nd cookie test, destroy cookie
		$lv -> destroyCookie($name);
		if ((isset($_COOKIE[$name]))) {
			echo "Testet för att förstöra en cookie misslyckades";
		}
	}

	//Test
	function testValidation() {
		$validation = new validate();
		if (!$validation -> validateEmail("daniel@student.lnu.se")) {
			echo('Fail email<br/>');
		}
		if (!$validation -> validateSocialSecurityNumber('870822-4616')) {
			echo('Fail SSN 870822-4616<br/>');
		}
		if (!$validation -> validateSocialSecurityNumber('8708224616')) {
			echo('Fail SSN 8708224616<br/>');
		}
		if (!$validation -> validateSocialSecurityNumber('198708224616')) {
			echo('Fail SSN 198708224616<br/>');
		}
		if (!$validation -> validateDate('1999-10-01')) {
			echo("Fail date 1999-10-01<br/>");
		}
		if (!$validation -> validateDate('99-10-01')) {
			echo("Fail date 99-10-01<br/>");
		}
		if (!$validation -> validateDate('991001')) {
			echo("Fail date 991001<br/>");
		}
		if ($validation -> validateDate('91001')) {
			echo("Fail date 91001<br/>");
		}
		if (!$validation -> validateNumber('111')) {
			echo("Fail date 111<br/>");
		}
		if ($validation -> validateNumber('aaaa')) {
			echo("Fail date aaaa<br/>");
		}
		if (!$validation -> validatePassword('!@#1zA')) {
			echo("Fail Password test <br/>");
		}
		echo($validation -> validateString(false, '<b>test b-tag, html = false</b>') . '<br/>');
		echo($validation -> validateString(true, '<b>test b-tag, html = true</b>') . '<br/>');
		echo($validation -> validateString(true, '<script>test script-tag, html = true</script>') . '<br/>');
	}

}
?>